// 在http.js中引入axios
import axios from 'axios'; // 引入axios
import QS from 'qs'; // 引入qs模块，用来序列化post类型的数据，后面会提到\
import router from "@/router";
const devBaseUrl = '/api';
const proBaseUrl = 'http://192.168.8.113/api';
// let url;
// url = process.env.NODE_ENV === 'development' ? devBaseUrl : proBaseUrl;
// // 设置超时时间
// axios.defaults.timeout = 10000;
// axios.defaults.baseURL = url;
// // 添加请求拦截器，在请求头中加token
// axios.interceptors.request.use(
//     config => {
//         if (localStorage.getItem('Authorization')) {
//             config.headers.Authorization = localStorage.getItem('Authorization');
//         }
//         return config;
//     },
//     error => {
//         return Promise.reject(error);
//     });

// // 设置默认post的请求头
// axios.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";



/**
 * get方法，对应get请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function get(url, params) {
    return new Promise((resolve, reject) => {
        axios.get(url, {
            params,
        }).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        });
    });
}

/**
 * post方法，对应post请求
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function post(url, params, contentType) {
    return new Promise((resolve, reject) => {
        axios.post(url, params, {
            headers: {
                "Content-Type": contentType ? contentType : "application/json",
            },
        }).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    });
}
/**
 * uploadFile  文件上传接口
 * @param {String} url [请求的url地址]
 * @param {Object} params [请求时携带的参数]
 */
export function uploadFile(params) {
    return new Promise((resolve, reject) => {
        axios.post('http://ajjj.pin100wan.com/api/member/upfile', params, {
            headers: {
                "Content-Type": "multipart/form-data"
            },
        }).then(res => {
            resolve(res);
        }).catch(err => {
            reject(err);
        })
    });
}